#ifndef MATERIAL_H
#define MATERIAL_H
#include <glm/glm.hpp>
#include <QString>
#include <vector>
#include <QGLWidget>
#include <QDataStream>


class Material
{
	friend QDataStream & operator>> (QDataStream & inStream, Material & material);
	friend QDataStream & operator<< (QDataStream & outStream, Material & material);

public:

	struct RenderInfo
	{
		QGLWidget * pDev;
		int texId;
		bool isNeedUpdate;
		int liveness;
	};

	Material ();

	~Material ();

	void setName (const QString & name);
	QString getName () const;

	void setAmbientColor (const glm::vec3 & color);
	glm::vec3 getAmbientColor () const;

	void setDiffuseColor (const glm::vec3 & color);
	glm::vec3 getDiffuseColor () const;

	void setSpecularColor (const glm::vec3 & color);
	glm::vec3 getSpecularColor () const;

	void setShininess (int shininess);
	int getShininess () const;

	void configMaterialAt (QGLWidget * pDev);

	void setTexImageName (const QString & texImageName);
	QString getTexImageName () const;

	void registerDev (QGLWidget * pDev);
	void removeDev (QGLWidget * pDev);
	RenderInfo * findRenderInfoByDev (QGLWidget * pDev);

private:

	QString _name;

	QString _texImageName;

	std::vector< RenderInfo > _renderInfos;

	glm::vec4 _ambientColor;
	glm::vec4 _diffuseColor;
	glm::vec4 _specularColor;
	int _shininess;

	void _rebindTexture (RenderInfo * pRenderInfo);
};

QDataStream & operator>> (QDataStream & inStream, Material & material);

QDataStream & operator<< (QDataStream & outStream, Material & material);


#endif // MATERIAL_H
